package com.rss.inbound.dao.impl;

// default package
// Generated Jan 10, 2013 11:00:14 PM by Hibernate Tools 3.4.0.CR1

import static org.hibernate.criterion.Example.create;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.rss.inbound.beans.CntnGeogrphy;
import com.rss.inbound.dao.CntnGeogrphyDAO;

/**
 * Home object for domain model class CntnGeogrphy.
 * 
 * @see .CntnGeogrphy
 * @author Hibernate Tools
 */
public class CntnGeogrphyDAOImpl extends HibernateDaoSupport implements
	CntnGeogrphyDAO
{

    private static final Log log	    = LogFactory
						    .getLog(CntnGeogrphyDAOImpl.class);

    private SessionFactory   sessionFactory = getSessionFactory();

    public void persist(CntnGeogrphy transientInstance)
    {
	log.debug("persisting CntnGeogrphy instance");
	try
	{
	    getHibernateTemplate().saveOrUpdate(transientInstance);
	    log.debug("persist successful");
	}
	catch (RuntimeException re)
	{
	    log.error("persist failed", re);
	    throw re;
	}
    }

    public void persistList(List<CntnGeogrphy> transientInstancesList)
    {
	log.debug("persisting CntnGeogrphy instance");
	try
	{
	    for (CntnGeogrphy cntnGeogrphy : transientInstancesList)
	    {
		getHibernateTemplate().saveOrUpdate(cntnGeogrphy);
	    }
	    log.debug("persist successful");
	}
	catch (RuntimeException re)
	{
	    log.error("persist failed", re);
	    throw re;
	}
    }

    public void attachDirty(CntnGeogrphy instance)
    {
	log.debug("attaching dirty CntnGeogrphy instance");
	try
	{
	    sessionFactory.getCurrentSession().saveOrUpdate(instance);
	    log.debug("attach successful");
	}
	catch (RuntimeException re)
	{
	    log.error("attach failed", re);
	    throw re;
	}
    }

    @SuppressWarnings("deprecation")
    public void attachClean(CntnGeogrphy instance)
    {
	log.debug("attaching clean CntnGeogrphy instance");
	try
	{
	    sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
	    log.debug("attach successful");
	}
	catch (RuntimeException re)
	{
	    log.error("attach failed", re);
	    throw re;
	}
    }

    public void delete(CntnGeogrphy persistentInstance)
    {
	log.debug("deleting CntnGeogrphy instance");
	try
	{
	    sessionFactory.getCurrentSession().delete(persistentInstance);
	    log.debug("delete successful");
	}
	catch (RuntimeException re)
	{
	    log.error("delete failed", re);
	    throw re;
	}
    }

    public CntnGeogrphy merge(CntnGeogrphy detachedInstance)
    {
	log.debug("merging CntnGeogrphy instance");
	try
	{
	    CntnGeogrphy result = (CntnGeogrphy) sessionFactory
		    .getCurrentSession().merge(detachedInstance);
	    log.debug("merge successful");
	    return result;
	}
	catch (RuntimeException re)
	{
	    log.error("merge failed", re);
	    throw re;
	}
    }

    public CntnGeogrphy findById(int id)
    {
	log.debug("getting CntnGeogrphy instance with id: " + id);
	try
	{
	    CntnGeogrphy instance = (CntnGeogrphy) sessionFactory
		    .getCurrentSession().get("CntnGeogrphy", id);
	    if (instance == null)
	    {
		log.debug("get successful, no instance found");
	    }
	    else
	    {
		log.debug("get successful, instance found");
	    }
	    return instance;
	}
	catch (RuntimeException re)
	{
	    log.error("get failed", re);
	    throw re;
	}
    }

    @SuppressWarnings("unchecked")
    public List<CntnGeogrphy> findByExample(CntnGeogrphy instance)
    {
	log.debug("finding CntnGeogrphy instance by example");
	try
	{
	    List<CntnGeogrphy> results = (List<CntnGeogrphy>) sessionFactory
		    .getCurrentSession().createCriteria("CntnGeogrphy")
		    .add(create(instance)).list();
	    log.debug("find by example successful, result size: "
		    + results.size());
	    return results;
	}
	catch (RuntimeException re)
	{
	    log.error("find by example failed", re);
	    throw re;
	}
    }
}

/*
 * protected SessionFactory getSessionFactory() { try { return (SessionFactory)
 * new InitialContext() .lookup("SessionFactory"); } catch (Exception e) {
 * log.error("Could not locate SessionFactory in JNDI", e); throw new
 * IllegalStateException( "Could not locate SessionFactory in JNDI"); } }
 */

/*
 * public SessionFactory getSessionFactory() { return sessionFactory; }
 * 
 * public void setSessionFactory(SessionFactory sessionFactory) {
 * this.sessionFactory = sessionFactory; }
 */